package com.gewu.pm.ui.activity.filter.config;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 筛选配置类
 */
public final class FilterConfig {
    
    private final List<FilterItem> items;
    
    private FilterConfig(Builder builder) {
        this.items = builder.items;
    }
    
    public List<FilterItem> getItems() {
        return items;
    }
    
    public static final class Builder {
        private final List<FilterItem> items = new ArrayList<>();
        
        /**
         * 添加文本选择器（单选）
         */
        public Builder addTextSelector(String key, String label, String hint, SelectorType selectorType) {
            items.add(new FilterItem.Builder()
                    .key(key)
                    .type(FilterType.TEXT_SELECTOR)
                    .label(label)
                    .hint(hint)
                    .selectorType(selectorType)
                    .multiSelect(false)
                    .build());
            return this;
        }
        
        /**
         * 添加文本选择器（支持单选/多选配置）
         */
        public Builder addTextSelector(String key, String label, String hint, SelectorType selectorType, boolean multiSelect) {
            items.add(new FilterItem.Builder()
                    .key(key)
                    .type(FilterType.TEXT_SELECTOR)
                    .label(label)
                    .hint(hint)
                    .selectorType(selectorType)
                    .multiSelect(multiSelect)
                    .build());
            return this;
        }
        
        /**
         * 添加文本选择器（支持自定义选项列表）
         * 
         * 用于 CUSTOM_LIST 类型，需要提供选项列表
         */
        public Builder addTextSelector(String key, String label, String hint, SelectorType selectorType, List<String> options) {
            items.add(new FilterItem.Builder()
                    .key(key)
                    .type(FilterType.TEXT_SELECTOR)
                    .label(label)
                    .hint(hint)
                    .selectorType(selectorType)
                    .options(options)
                    .multiSelect(false)
                    .build());
            return this;
        }
        
        /**
         * 添加文本选择器（支持自定义选项列表和单选/多选配置）
         * 
         * 用于 CUSTOM_LIST 类型，需要提供选项列表
         */
        public Builder addTextSelector(String key, String label, String hint, SelectorType selectorType, List<String> options, boolean multiSelect) {
            items.add(new FilterItem.Builder()
                    .key(key)
                    .type(FilterType.TEXT_SELECTOR)
                    .label(label)
                    .hint(hint)
                    .selectorType(selectorType)
                    .options(options)
                    .multiSelect(multiSelect)
                    .build());
            return this;
        }
        
        /**
         * 添加标签选择器（单选）
         */
        public Builder addTagSelector(String key, String label, List<String> options, int columnCount) {
            items.add(new FilterItem.Builder()
                    .key(key)
                    .type(FilterType.TAG_SELECTOR)
                    .label(label)
                    .options(options)
                    .columnCount(columnCount)
                    .build());
            return this;
        }
        
        /**
         * 添加标签选择器（单选）- 可变参数
         */
        public Builder addTagSelector(String key, String label, int columnCount, String... options) {
            return addTagSelector(key, label, Arrays.asList(options), columnCount);
        }
        
        /**
         * 添加多选标签选择器
         */
        public Builder addMultiTagSelector(String key, String label, List<String> options, int columnCount) {
            items.add(new FilterItem.Builder()
                    .key(key)
                    .type(FilterType.MULTI_TAG_SELECTOR)
                    .label(label)
                    .options(options)
                    .columnCount(columnCount)
                    .build());
            return this;
        }
        
        /**
         * 添加多选标签选择器 - 可变参数
         */
        public Builder addMultiTagSelector(String key, String label, int columnCount, String... options) {
            return addMultiTagSelector(key, label, Arrays.asList(options), columnCount);
        }
        
        /**
         * 添加时间选择器
         */
        public Builder addTimeSelector(String key, String label, int columnCount) {
            List<String> timeOptions = Arrays.asList(
                    "今日", "昨日", "本周", "本月", 
                    "近7天", "近30天", "近90天", "自定义"
            );
            items.add(new FilterItem.Builder()
                    .key(key)
                    .type(FilterType.TIME_SELECTOR)
                    .label(label)
                    .options(timeOptions)
                    .columnCount(columnCount)
                    .build());
            return this;
        }
        
        /**
         * 添加日期范围选择器
         */
        public Builder addDateRangeSelector(String key, String label) {
            items.add(new FilterItem.Builder()
                    .key(key)
                    .type(FilterType.DATE_RANGE_SELECTOR)
                    .label(label)
                    .build());
            return this;
        }
        
        /**
         * 添加金额范围选择器
         */
        public Builder addAmountRangeSelector(String key, String label) {
            items.add(new FilterItem.Builder()
                    .key(key)
                    .type(FilterType.AMOUNT_RANGE_SELECTOR)
                    .label(label)
                    .build());
            return this;
        }
        
        public FilterConfig build() {
            return new FilterConfig(this);
        }
    }
}
